/**   
 * @Title: DigitLotteryLatestInfoCommunicater.java 
 * @Package com.esun.rabbit2.communicaters.lotteryinfo 
 * @Description: TODO(用一句话描述该文件做什么) 
 * @author: Billy Qigs@500wan.com   
 * @date: 2012-1-5 下午2:50:31  
 * Copyright: (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.communicaters.lotteryinfo;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.client.ClientProtocolException;
import org.xml.sax.SAXException;

import com.esun.config.BussinessCode;
import com.esun.config.Config;
import com.esun.config.Key;
import com.esun.model.DigitLotteryLatestInfo;
import com.esun.network.ServerCommunicater;
import com.esun.util.log.EDebug;

/**
 * @ClassName: DigitLotteryLatestInfoCommunicater
 * @Description: (数字彩当前开奖信息)
 * @author: Billy Qigs@500wan.com
 * @date: 2012-1-5 下午2:50:31
 * 
 */
public class DigitLotteryLatestInfoCommunicater extends ServerCommunicater {

	private String serverMsg = "";
	private ArrayList<Hashtable<String, String>> listResult = new ArrayList<Hashtable<String, String>>();

	public boolean isGetDigitLotteryLatestInfoSucceed() throws ClientProtocolException, IOException, ParserConfigurationException, SAXException {

		boolean isSucceed = false;

		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		list.add(mapItem(BussinessCode.PASER_MID, BussinessCode.MID_GET_DIGIT_LOTTERY_LATEST_INFO));
		list.add(mapItem(BussinessCode.PASER_CK, Config.NULLMARK));

		// 写入服务器返回信息
		super.getServerResponse(list, true);
		if (super.getState() == 100) {
			isSucceed = true;
			setServerMessage(super.getServerMsg());
			listResult = super.getListResult();
			if (super.getListResult().size() == 0) {
				EDebug.o("list 为空");
				isSucceed = false;
			} else {
				EDebug.o("list 不为空");
			}
		} else {
			isSucceed = false;
		}
		return isSucceed;

	}

	public String getServerMessage() {
		return serverMsg;
	}

	private void setServerMessage(String str) {
		serverMsg = str;
	}

	public void updateLotteryInfo() {

		DigitLotteryLatestInfo.getDigitLotteryLatestInfo().cleanup();

		for (int i = 0; i < listResult.size(); i++) {

			String lotid = listResult.get(i).get(Key.KEY_LOTID);
			String expect = listResult.get(i).get(Key.KEY_EXPECT);
			String openCode = listResult.get(i).get(Key.KEY_LOTT_OPENCODE);
			EDebug.o(this, "lotid = " + lotid);
			switch (Integer.valueOf(lotid)) {

			case 3:
				// 双色球
				DigitLotteryLatestInfo.getDigitLotteryLatestInfo().setSSQLatestInfo(lotid, expect, openCode);

				break;

			case 28:
				// 大乐透
				DigitLotteryLatestInfo.getDigitLotteryLatestInfo().setDLTLatestInfo(lotid, expect, openCode);
				break;

			case 45:
				// 11选5
				DigitLotteryLatestInfo.getDigitLotteryLatestInfo().setSYXWLatestInfo(lotid, expect, openCode);
				break;

			case 7:
				// 福彩3D
				DigitLotteryLatestInfo.getDigitLotteryLatestInfo().setFC3DLatestInfo(lotid, expect, openCode);
				break;

			case 29:
				// 时时彩
				DigitLotteryLatestInfo.getDigitLotteryLatestInfo().setSSCLatestInfo(lotid, expect, openCode);
				break;

			case 1:
				// 任选9/足球胜负
				DigitLotteryLatestInfo.getDigitLotteryLatestInfo().setRXJLatestInfo(lotid, expect, openCode);
				break;

			case 4:
				// 七星彩
				DigitLotteryLatestInfo.getDigitLotteryLatestInfo().setQXCLatestInfo(lotid, expect, openCode);
				break;

			case 11:
				// 七乐彩
				DigitLotteryLatestInfo.getDigitLotteryLatestInfo().setQLCLatestInfo(lotid, expect, openCode);
				break;

			case 8:
				// 22选5
				DigitLotteryLatestInfo.getDigitLotteryLatestInfo().setEEXWLatestInfo(lotid, expect, openCode);
				break;

			case 5:
				// 排列三
				DigitLotteryLatestInfo.getDigitLotteryLatestInfo().setPLSLatestInfo(lotid, expect, openCode);
				break;

			case 10001:
				// 排列五
				DigitLotteryLatestInfo.getDigitLotteryLatestInfo().setPLWLatestInfo(lotid, expect, openCode);
				break;

			}

		}

	}

	private HashMap<String, String> mapItem(String name, String value) {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put(name, value);
		return map;
	}

}
